<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>claein.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CLAEIN.1"></a><a href="claein.f.html#CLAEIN.1">CLAEIN</a>( RIGHTV, NOINIT, N, H, LDH, W, V, B, LDB, RWORK,
     $                   EPS3, SMLNUM, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK auxiliary routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      LOGICAL            NOINIT, RIGHTV
      INTEGER            INFO, LDB, LDH, N
      REAL               EPS3, SMLNUM
      COMPLEX            W
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      REAL               RWORK( * )
      COMPLEX            B( LDB, * ), H( LDH, * ), V( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="CLAEIN.22"></a><a href="claein.f.html#CLAEIN.1">CLAEIN</a> uses inverse iteration to find a right or left eigenvector
</span><span class="comment">*</span><span class="comment">  corresponding to the eigenvalue W of a complex upper Hessenberg
</span><span class="comment">*</span><span class="comment">  matrix H.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  RIGHTV   (input) LOGICAL
</span><span class="comment">*</span><span class="comment">          = .TRUE. : compute right eigenvector;
</span><span class="comment">*</span><span class="comment">          = .FALSE.: compute left eigenvector.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  NOINIT   (input) LOGICAL
</span><span class="comment">*</span><span class="comment">          = .TRUE. : no initial vector supplied in V
</span><span class="comment">*</span><span class="comment">          = .FALSE.: initial vector supplied in V.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The order of the matrix H.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  H       (input) COMPLEX array, dimension (LDH,N)
</span><span class="comment">*</span><span class="comment">          The upper Hessenberg matrix H.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDH     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array H.  LDH &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  W       (input) COMPLEX
</span><span class="comment">*</span><span class="comment">          The eigenvalue of H whose corresponding right or left
</span><span class="comment">*</span><span class="comment">          eigenvector is to be computed.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  V       (input/output) COMPLEX array, dimension (N)
</span><span class="comment">*</span><span class="comment">          On entry, if NOINIT = .FALSE., V must contain a starting
</span><span class="comment">*</span><span class="comment">          vector for inverse iteration; otherwise V need not be set.
</span><span class="comment">*</span><span class="comment">          On exit, V contains the computed eigenvector, normalized so
</span><span class="comment">*</span><span class="comment">          that the component of largest magnitude has magnitude 1; here
</span><span class="comment">*</span><span class="comment">          the magnitude of a complex number (x,y) is taken to be
</span><span class="comment">*</span><span class="comment">          |x| + |y|.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  B       (workspace) COMPLEX array, dimension (LDB,N)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDB     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array B.  LDB &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  RWORK   (workspace) REAL array, dimension (N)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  EPS3    (input) REAL
</span><span class="comment">*</span><span class="comment">          A small machine-dependent value which is used to perturb
</span><span class="comment">*</span><span class="comment">          close eigenvalues, and to replace zero pivots.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  SMLNUM  (input) REAL
</span><span class="comment">*</span><span class="comment">          A machine-dependent value close to the underflow threshold.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit
</span><span class="comment">*</span><span class="comment">          = 1:  inverse iteration did not converge; V is set to the
</span><span class="comment">*</span><span class="comment">                last iterate.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      REAL               ONE, TENTH
      PARAMETER          ( ONE = 1.0E+0, TENTH = 1.0E-1 )
      COMPLEX            ZERO
      PARAMETER          ( ZERO = ( 0.0E+0, 0.0E+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      CHARACTER          NORMIN, TRANS
      INTEGER            I, IERR, ITS, J
      REAL               GROWTO, NRMSML, ROOTN, RTEMP, SCALE, VNORM
      COMPLEX            CDUM, EI, EJ, TEMP, X
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      INTEGER            ICAMAX
      REAL               SCASUM, SCNRM2
      COMPLEX            <a name="CLADIV.94"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>
      EXTERNAL           ICAMAX, SCASUM, SCNRM2, <a name="CLADIV.95"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="CLATRS.98"></a><a href="clatrs.f.html#CLATRS.1">CLATRS</a>, CSSCAL
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          ABS, AIMAG, MAX, REAL, SQRT
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Statement Functions ..
</span>      REAL               CABS1
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Statement Function definitions ..
</span>      CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( CDUM ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     GROWTO is the threshold used in the acceptance test for an
</span><span class="comment">*</span><span class="comment">     eigenvector.
</span><span class="comment">*</span><span class="comment">
</span>      ROOTN = SQRT( REAL( N ) )
      GROWTO = TENTH / ROOTN
      NRMSML = MAX( ONE, EPS3*ROOTN )*SMLNUM
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Form B = H - W*I (except that the subdiagonal elements are not
</span><span class="comment">*</span><span class="comment">     stored).
</span><span class="comment">*</span><span class="comment">
</span>      DO 20 J = 1, N
         DO 10 I = 1, J - 1
            B( I, J ) = H( I, J )
   10    CONTINUE
         B( J, J ) = H( J, J ) - W
   20 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      IF( NOINIT ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Initialize V.
</span><span class="comment">*</span><span class="comment">
</span>         DO 30 I = 1, N
            V( I ) = EPS3
   30    CONTINUE
      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Scale supplied initial vector.
</span><span class="comment">*</span><span class="comment">
</span>         VNORM = SCNRM2( N, V, 1 )
         CALL CSSCAL( N, ( EPS3*ROOTN ) / MAX( VNORM, NRMSML ), V, 1 )
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( RIGHTV ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        LU decomposition with partial pivoting of B, replacing zero
</span><span class="comment">*</span><span class="comment">        pivots by EPS3.
</span><span class="comment">*</span><span class="comment">
</span>         DO 60 I = 1, N - 1
            EI = H( I+1, I )
            IF( CABS1( B( I, I ) ).LT.CABS1( EI ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Interchange rows and eliminate.
</span><span class="comment">*</span><span class="comment">
</span>               X = <a name="CLADIV.156"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>( B( I, I ), EI )
               B( I, I ) = EI
               DO 40 J = I + 1, N
                  TEMP = B( I+1, J )
                  B( I+1, J ) = B( I, J ) - X*TEMP
                  B( I, J ) = TEMP
   40          CONTINUE
            ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Eliminate without interchange.
</span><span class="comment">*</span><span class="comment">
</span>               IF( B( I, I ).EQ.ZERO )
     $            B( I, I ) = EPS3
               X = <a name="CLADIV.169"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>( EI, B( I, I ) )
               IF( X.NE.ZERO ) THEN
                  DO 50 J = I + 1, N
                     B( I+1, J ) = B( I+1, J ) - X*B( I, J )
   50             CONTINUE
               END IF
            END IF
   60    CONTINUE
         IF( B( N, N ).EQ.ZERO )
     $      B( N, N ) = EPS3
<span class="comment">*</span><span class="comment">
</span>         TRANS = <span class="string">'N'</span>
<span class="comment">*</span><span class="comment">
</span>      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        UL decomposition with partial pivoting of B, replacing zero
</span><span class="comment">*</span><span class="comment">        pivots by EPS3.
</span><span class="comment">*</span><span class="comment">
</span>         DO 90 J = N, 2, -1
            EJ = H( J, J-1 )
            IF( CABS1( B( J, J ) ).LT.CABS1( EJ ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Interchange columns and eliminate.
</span><span class="comment">*</span><span class="comment">
</span>               X = <a name="CLADIV.193"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>( B( J, J ), EJ )
               B( J, J ) = EJ
               DO 70 I = 1, J - 1
                  TEMP = B( I, J-1 )
                  B( I, J-1 ) = B( I, J ) - X*TEMP
                  B( I, J ) = TEMP
   70          CONTINUE
            ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Eliminate without interchange.
</span><span class="comment">*</span><span class="comment">
</span>               IF( B( J, J ).EQ.ZERO )
     $            B( J, J ) = EPS3
               X = <a name="CLADIV.206"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>( EJ, B( J, J ) )
               IF( X.NE.ZERO ) THEN
                  DO 80 I = 1, J - 1
                     B( I, J-1 ) = B( I, J-1 ) - X*B( I, J )
   80             CONTINUE
               END IF
            END IF
   90    CONTINUE
         IF( B( 1, 1 ).EQ.ZERO )
     $      B( 1, 1 ) = EPS3
<span class="comment">*</span><span class="comment">
</span>         TRANS = <span class="string">'C'</span>
<span class="comment">*</span><span class="comment">
</span>      END IF
<span class="comment">*</span><span class="comment">
</span>      NORMIN = <span class="string">'N'</span>
      DO 110 ITS = 1, N
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Solve U*x = scale*v for a right eigenvector
</span><span class="comment">*</span><span class="comment">          or U'*x = scale*v for a left eigenvector,
</span><span class="comment">*</span><span class="comment">        overwriting x on v.
</span><span class="comment">*</span><span class="comment">
</span>         CALL <a name="CLATRS.228"></a><a href="clatrs.f.html#CLATRS.1">CLATRS</a>( <span class="string">'Upper'</span>, TRANS, <span class="string">'Nonunit'</span>, NORMIN, N, B, LDB, V,
     $                SCALE, RWORK, IERR )
         NORMIN = <span class="string">'Y'</span>
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Test for sufficient growth in the norm of v.
</span><span class="comment">*</span><span class="comment">
</span>         VNORM = SCASUM( N, V, 1 )
         IF( VNORM.GE.GROWTO*SCALE )
     $      GO TO 120
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Choose new orthogonal starting vector and try again.
</span><span class="comment">*</span><span class="comment">
</span>         RTEMP = EPS3 / ( ROOTN+ONE )
         V( 1 ) = EPS3
         DO 100 I = 2, N
            V( I ) = RTEMP
  100    CONTINUE
         V( N-ITS+1 ) = V( N-ITS+1 ) - EPS3*ROOTN
  110 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Failure to find eigenvector in N iterations.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 1
<span class="comment">*</span><span class="comment">
</span>  120 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Normalize eigenvector.
</span><span class="comment">*</span><span class="comment">
</span>      I = ICAMAX( N, V, 1 )
      CALL CSSCAL( N, ONE / CABS1( V( I ) ), V, 1 )
<span class="comment">*</span><span class="comment">
</span>      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CLAEIN.261"></a><a href="claein.f.html#CLAEIN.1">CLAEIN</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
